<?php
include_once("./function.php");
$sql="select * from ts_news_cate";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if((mysqli_num_rows($res))>0)
	{
		$pro=array();
		while($list=mysqli_fetch_assoc($res))
		{
			$pro[]=$list;
		}
		//print_r($pro);die;//Array ( [0] => Array ( [pc_id] => 1 [pc_fid] => 0 [pc_name] => 服装 [pc_level] => 1 [ifshow] => 0 ) )
	}
}
$sql="select * from ts_news";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if((mysqli_num_rows($res))>0)
	{
		$ts_p=array();
		while($list=mysqli_fetch_assoc($res))
		{
			$ts_p[]=$list;
		}
		//print_r($ts_p);die;Array ( [0] => Array ( [pid] => 1 [p_c_id] => 10 [pname] => 牛仔裤 [price] => 299.00 [thumb] => [descp] => [pubtime] => 11 [addr] => 杭州 [color] => black [size] => [ifshow] => 1 [sprice] => [keyword] => [snums] => [pnums] => 005 [pimgs] => ) )
	}
}
//无线分类
function card($arr,$fid)
{
	static $new=array();
	foreach($arr as $v)
	{
		if($v['fid']==$fid)
		{
			$new[]=$v;
			card($arr,$v['cid']);
		}
	}
	return $new;
}
$pro=card($pro,0);	
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>商品添加</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
<style>.sp{display:inline-block;} .sp_color{width:35px;display:inline-block;padding:0px;border:0px;background:#fff;}</style>
</head>
<body leftmargin="8" topmargin='8'>
<form action="do_news_add.php" method="post" id="form" onsubmit="return check();" enctype="multipart/form-data">
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2"><span><img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>添加新闻</span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>
		<table style="margin-bottom:8px;margin-top:8px;margin-left:20px;">
		<tr>
			<td>新闻标题:</td>
			<td>
				<input type="text" name="title" value=""/><font color="red">*</font>
				<span id="tip_t" class="sp"></span>
			</td>	
		</tr>
			 <tr>
				<td width="100px;">新闻分类:</td>
				<td>
				<select name="id">
					<option value="0">顶级分类</option>
					<?php foreach($pro as $v){?>
						<option value="<?=$v['cid']?>"
					<?php 
					$sql="select * from ts_news_cate where fid=".$v["cid"];
					$res=mysqli_query($link,$sql);
					if((mysqli_num_rows($res))>0){?>disabled
					<?php }?>
					><?=str_repeat("&nbsp;",3*($v['level']-1)).$v['cname']?></option>
					<?php }?>
			</select><font color="red">*</font>
					<span id="tip_f" class="sp">
				</td>
			  </tr>
			   <tr>
				 <td>作者:</td>
				 <td><input type="text" name="author" value=""/><font color="red">*</font><span id="tip_a" class="sp"></span></td>
			   </tr>
			   <tr>
				 <td>关键字:</td>
				 <td><input type="text" name="keyword" value=""/></td>
			   </tr>
			   <tr>
				 <td>描述:</td>
				 <td><input type="text" name="description" value=""/></td>
			   </tr>
			   <tr>
					<td>新闻配图:</td>
					<td><span id="spa" onclick="create1();" style="font-size:20px;">+</span><input type="file" name="img[]"><span id="second"></span></td>
			   </tr>
			   <tr>
					<td>新闻内容</td>
					<td><textarea name="text" id="" cols="30" rows="10"></textarea><span id="tip_p"></span></td>
			   </tr>
			   <tr>
				 <td colspan="2" align="left" height="40px">
					<input type="submit" name="sub" value="添加" style="background:#ffffcc;margin-left:100px;"/>
				 </td>
			   </tr>
		</table>
	</td>
  </tr>
</table>
</form>
<script type="text/javascript">
	tip_t=document.getElementById("tip_t");
	tip_a=document.getElementById("tip_a");
	tip_p=document.getElementById("tip_p");
	function getValue(obj,tip)
	{
		if(obj.value=="")
		{
			tip.style.color="red";
			tip.innerHTML="不能为空";
		}
		else
		{
			tip.innerHTML="";
		}
	}
	form.title.onblur=function()
	{
		getValue(form.title,tip_t);
	}

	form.author.onblur=function()
	{
		getValue(form.author,tip_a);
	}
	form.text.onblur=function()
	{
		getValue(form.text,tip_p);
	}
	
	second=document.getElementById("second");
	function create1()
	{
		//以下节点的创建内容包裹在下面创建的div中
		br=document.createElement('br');        
		second.appendChild(br);
		span=document.createElement('span'); 
		span.setAttribute('onclick','del2();');
		span.setAttribute('style','font-size:25px;');
		d=document.createTextNode('-');
		span.appendChild(d);
		second.appendChild(span);
		//元素节点的创建
		inp=document.createElement('input');
		inp.setAttribute('type','file');
		inp.setAttribute('name','simg[]');
		//inp.setAttribute('style','width:35px;padding:0px;border:0px;background:#fff;')
		second.appendChild(inp);
	}
	function del2()
	{
		second.removeChild(second.lastChild);
	}
	function check()
	{
		if(form.title.value==""||form.author.value==""||form.text.value=="")
		{
			alert("新闻标题,作者,内容不能为空");
			return false;
		}
		return true;
	}
</script>
</body>
</html>

